(function($) {
	var rw = '',applyType ='',nurseid,maxRole;
	var method,className,statusKey,TomcatUrl
	$.init();
	$.plusReady(function() {
		baseSetup();
	});
	function baseSetup() {
		mui('.mui-scroll-wrapper').scroll();
		mui.previewImage();
		var self = plus.webview.currentWebview();
		var pageData = self.pageData;
		// console.log(JSON.stringify(pageData));
		var type = self.type
		var perInfo = app.getState()
		if (perInfo) {
			nurseid = perInfo.loginID
			if(perInfo.maxRoleLevel){
				maxRole = parseInt(perInfo.maxRoleLevel)
			}else{
				mui.toast('用户未配置角色，可能会出现上报异常，请联系管理员登录护理管理系统，进入“系统设置” -> ”用户角色设置”进行配置！')
				return
			}
			TomcatUrl = perInfo.TomcatUrl
		}
		plus.storage.removeItem('detail');
		var fromPage = self.fromPage
		rw = pageData.RowID;
		applyType = self.applyType;
		var flagStr = pageData['RecFlag']
		var scroll = document.getElementById('scroll');
		var title = document.getElementById('title');
		var html = '';
		if (type == 'award') {
			method = 'web.INMPerSubComm:SaveResearchAward'
			className = 'DHCINM.HR.MgResearchAward'
			statusKey = 'RecFlag'
			title.innerHTML = '科研获奖';
			// console.log(JSON.stringify(pageData));
			var fir = pageData['ScienFirPer']
			var sec = pageData['ScienSecPer']
			var third = pageData['ScienThirdPer']
			if (fir != '') {
				fir = pageData['ScienFirPerDesc']+' - '+pageData['ScienFirHeadDesc']+' - '+
					pageData['ScienFirDutyDesc']+' - '+pageData['ScienFirNo']+'<br />'+
					pageData['ScienFirBigDesc']+'<br />'+pageData['ScienFirLocDesc']
			}
			if (sec != '') {
				sec = pageData['ScienSecPerDesc']+' - '+pageData['ScienSecHeadDesc']+' - '+
					pageData['ScienSecDutyDesc']+' - '+pageData['ScienSecLevDesc']+'<br />'+
					pageData['ScienSecBigDesc']+'<br />'+pageData['ScienSecLocDesc']
			}
			if (third != '') {
				third = pageData['ScienThirdPerDesc']+' - '+pageData['ScienThirdHeadDesc']+' - '+
					pageData['ScienThirdDutyDesc']+' - '+pageData['ScienThirdLevDesc']+'<br />'+
					pageData['ScienThirdBigDesc']+'<br />'+pageData['ScienThirdLocDesc']
			}
			html = '<div class="textTip">奖项名称</div><div class="textContent">'+pageData['ScienName']+'</div>'+
				'<div class="textTip">奖项来源</div><div class="textContent">'+pageData['ScienSourceDesc']+'</div>'+
				'<div class="textTip">获奖等级</div><div class="textContent">'+pageData['ScienGradeDesc']+'</div>'+
				'<div class="textTip">获奖日期</div><div class="textContent">'+pageData['ScienDate']+'</div>'+
				'<div class="textTip">获奖项目名称</div><div class="textContent">'+pageData['ScienPrjName']+'</div>'+
				'<div class="textTip">奖金数额</div><div class="textContent">'+pageData['ScienBonuses']+'</div>'+
				'<div class="textTip">获奖类型</div><div class="textContent">'+pageData['ScienTypeDesc']+'</div>'+
				'<div class="textTip">颁奖单位名称</div><div class="textContent">'+pageData['SciAwardOrg']+'</div>'+
				'<div class="textTip">第一完成人</div><div class="textContent">'+fir+'</div>'+
				'<div class="textTip">第二完成人</div><div class="textContent">'+sec+'</div>'+
				'<div class="textTip">第三完成人</div><div class="textContent">'+third+'</div>'+
				'<div class="textTip">其它完成人</div><div class="textContent">'+pageData['ScienOtPer']+'</div>'+
				'<div class="textTip">备注</div><div class="textContent">'+pageData['otherRemark']+'</div>';
		}else if (type == 'topic') {
			method = 'web.INMPerSubComm:SaveResearchProject'
			className = 'DHCINM.HR.MgResearchProject'
			statusKey = 'RecFlag'
			title.innerHTML = '课题立项';
			var fir = pageData['firresponser']
			var sec = pageData['secrespon']
			if (fir != '') {
				fir = pageData['FirstResponserDesc']+' - '+pageData['FirResponerHeadDesc']+' - '+
					pageData['FirResponerDutyDesc']+' - '+pageData['FirResponerNo']+'<br />'+
					pageData['FirResponerBigDesc']+'<br />'+pageData['FirResponerLocDesc']
			}
			if (sec != '') {
				sec = pageData['SecondResponserDesc']+' - '+pageData['SecResponerHeadDesc']+' - '+
					pageData['SecResponerDutyDesc']+' - '+pageData['SecResponerLevDesc']+'<br />'+
					pageData['SecResponerBigDesc']+'<br />'+pageData['SecResponerLocDesc']
			}
			html = '<div class="textTip">课题名称</div><div class="textContent">'+pageData['ProjectName']+'</div>'+
				'<div class="textTip">项目编号</div><div class="textContent">'+pageData['ProjectNo']+'</div>'+
				'<div class="textTip">课题等级</div><div class="textContent">'+pageData['ProjectGradeDesc']+'</div>'+
				'<div class="textTip">立项日期</div><div class="textContent">'+pageData['ProjectDate']+'</div>'+
				'<div class="textTip">预计完成日期</div><div class="textContent">'+pageData['FinishDate']+'</div>'+
				'<div class="textTip">项目类型</div><div class="textContent">'+pageData['ProjectTypeDesc']+'</div>'+
				'<div class="textTip">资金来源</div><div class="textContent">'+pageData['ProjectFundSrc']+'</div>'+
				'<div class="textTip">获批科研经费</div><div class="textContent">'+pageData['ProjectSpotExpense']+'</div>'+
				'<div class="textTip">总负责人</div><div class="textContent">'+fir+'</div>'+
				'<div class="textTip">第二负责人</div><div class="textContent">'+sec+'</div>'+
				'<div class="textTip">第三负责人</div><div class="textContent">'+pageData['ThirdResponserDesc']+'</div>'+
				'<div class="textTip">所有获奖者</div><div class="textContent">'+pageData['OtherResponser']+'</div>'+
				// '<div class="textTip">结题日期</div><div class="textContent">'+pageData['ConcludeDate']+'</div>'+
				'<div class="textTip">备注</div><div class="textContent">'+pageData['ProjectRemark']+'</div>';
			
		}else if (type == 'patent') {
			method = 'web.INMPerSubComm:SavePatent'
			className = 'DHCINM.HR.MgPatent'
			statusKey = 'PatValid'
			flagStr = pageData['PatValid']
			title.innerHTML = '护理专利';
			var fir = pageData['PatFirInventor']
			if (fir != '') {
				if (pageData['PatFirInventorDesc'] != '') {
					fir = pageData['PatFirInventorDesc']
				}
				var PatFirInvNo = pageData['PatFirInvNo']?pageData['PatFirInvNo']:''
				fir += '-'+pageData['PatFirInvCallDesc']+' - '+
					pageData['PatFirInvDutyDesc']+' - '+pageData['PatFirInvLevelDesc']+' - '+PatFirInvNo+'<br />'+
					pageData['PatFirInvBigRoomDesc']+'<br />'+pageData['PatFirInvRoomDesc']
			}
			html = '<div class="textTip">专利名称</div><div class="textContent">'+pageData['PatName']+'</div>'+
				'<div class="textTip">专利权人</div><div class="textContent">'+pageData['PatPerson']+'</div>'+
				'<div class="textTip">专利类型</div><div class="textContent">'+pageData['PatTypeDesc']+'</div>'+
				'<div class="textTip">专利号</div><div class="textContent">'+pageData['PatNum']+'</div>'+
				'<div class="textTip">授权公告号</div><div class="textContent">'+pageData['PatCerNum']+'</div>'+
				'<div class="textTip">第一发明人</div><div class="textContent">'+fir+'</div>'+
				'<div class="textTip">第二发明人</div><div class="textContent">'+pageData['PatSecInventorDesc']+'</div>'+
				'<div class="textTip">第三发明人</div><div class="textContent">'+pageData['PatThiInventorDesc']+'</div>'+
				'<div class="textTip">其它发明人</div><div class="textContent">'+pageData['PatOthInventor']+'</div>'+
				'<div class="textTip">发明申请日</div><div class="textContent">'+pageData['PatAppDate']+'</div>'+
				'<div class="textTip">专利授权公告日</div><div class="textContent">'+pageData['PatAutAnnDate']+'</div>'+
				// '<div class="textTip">专利权期限</div><div class="textContent">'+pageData['PatLife']+'</div>'+
				'<div class="textTip">授权单位</div><div class="textContent">'+pageData['PatAutUnitDesc']+'</div>'+
				'<div class="textTip">备注</div><div class="textContent">'+pageData['PatRemark']+'</div>';
		}else if(type == 'artical'){
			method = 'web.INMPerSubComm:SaveArticle'
			className = 'DHCINM.HR.MgArticle'
			statusKey = 'ArtValid'
			title.innerHTML = '文章管理';
			// console.log('pageData :>> ', pageData);
			flagStr = pageData['ArtValid']
			var fir = pageData['ArtFirAuthor']
			if (fir != '') {
				fir = pageData['ArtFirAuthor']+' - '+pageData['ArtFirAuthorHeadDesc']+' - '+
					pageData['ArtFirAuthorDutyDesc']+'<br />'+
					pageData['ArtFirAuthorBigDesc']+'<br />'+pageData['ArtFirAuthorLocDesc']
			}
			
			html = '<div class="textTip">文章题目</div><div class="textContent">'+pageData['ArtTitle']+'</div>'+
				'<div class="textTip">杂志类别</div><div class="textContent">'+pageData['ArtCategoryDesc']+'</div>'+
				'<div class="textTip">影响因子</div><div class="textContent">'+pageData['ArtFactor']+'</div>'+
				'<div class="textTip">杂志名称</div><div class="textContent">'+pageData['ArtMagazineDesc']+'</div>'+
				'<div class="textTip">发表日期</div><div class="textContent">'+pageData['ArtDate']+'</div>'+
				'<div class="textTip">文章类型</div><div class="textContent">'+pageData['ArtTypeDesc']+'</div>'+
				'<div class="textTip">卷/期/页面</div><div class="textContent">'+'第'+pageData['ArtVolume']+
					'卷&nbsp;&nbsp;第'+pageData['ArtTerm']+'期&nbsp;&nbsp;第'+pageData['ArtPage']+'页'+'</div>'+
				'<div class="textTip">发表栏目</div><div class="textContent">'+pageData['ArtHeadingDesc']+'</div>'+
				'<div class="textTip">作者类型</div><div class="textContent">'+(pageData['ArtAuthorTypeDesc'])+'</div>'+
				'<div class="textTip">所有作者</div><div class="textContent">'+(pageData['AllAuthor'])+'</div>'+
				'<div class="textTip">作者</div><div class="textContent">'+fir+'</div>';
		}else if(type == 'work'){ //著作
			method = 'web.INMSMComm:SaveSciWork'
			className = 'DHCINM.SM.SciWork'
			statusKey = 'RecFlag'
			title.innerHTML = '著作';
			// console.log('pageData :>> ', pageData);
			flagStr = pageData['RecFlag']
			var fir = pageData['AuthorDesc']+' - '+pageData['AuthorNo']+' - '+(pageData['AuthorLvDesc']||'')+'<br />'+
				(pageData['AuthorHireDesc']||'')+' - '+(pageData['AuthorPostDesc']||'')+'<br />'+
				(pageData['AuthorBigDesc']||'')+'<br />'+(pageData['AuthorLocDesc']||'')
			
			html = '<div class="textTip">书名</div><div class="textContent">'+pageData['BookName']+'</div>'+
				'<div class="textTip">著作类型</div><div class="textContent">'+pageData['WorkTypeDesc']+'</div>'+
				'<div class="textTip">出版类型</div><div class="textContent">'+pageData['PressTypeDesc']+'</div>'+
				'<div class="textTip">出版社名称</div><div class="textContent">'+pageData['PressName']+'</div>'+
				'<div class="textTip">出版日期</div><div class="textContent">'+pageData['PublishDate']+'</div>'+
				'<div class="textTip">书籍ISBN号</div><div class="textContent">'+pageData['BookNo']+'</div>'+
				'<div class="textTip">中国图书馆CIP核字</div><div class="textContent">'+pageData['CipNo']+'</div>'+
				'<div class="textTip">作者类型</div><div class="textContent">'+(pageData['AuthorTypeDesc'])+'</div>'+
				'<div class="textTip">著作作者</div><div class="textContent">'+fir+'</div>'+
				'<div class="textTip">所有作者</div><div class="textContent">'+(pageData['AllAuthor'])+'</div>';
		}else if(type == 'trans'){ //成果转化
			method = 'web.INMSMComm:SaveSciTrans'
			className = 'DHCINM.SM.SciTrans'
			statusKey = 'RecFlag'
			title.innerHTML = '成果转化';
			// console.log('pageData :>> ', pageData);
			flagStr = pageData['RecFlag']
			html = '<div class="textTip">成果名称</div><div class="textContent">'+pageData['WorkName']+'</div>'+
				'<div class="textTip">专利类型</div><div class="textContent">'+pageData['PatentTypeDesc']+'</div>'+
				'<div class="textTip">转化方式</div><div class="textContent">'+pageData['TransTypeDesc']+'</div>'+
				'<div class="textTip">提成方式</div><div class="textContent">'+pageData['TakeTypeDesc']+'</div>'+
				'<div class="textTip">受让单位</div><div class="textContent">'+pageData['TransOrg']+'</div>'+
				'<div class="textTip">受让单位联系人</div><div class="textContent">'+pageData['TransPer']+'</div>'+
				'<div class="textTip">受让单位联系方式</div><div class="textContent">'+pageData['TransPhone']+'</div>'+
				'<div class="textTip">合同编号</div><div class="textContent">'+pageData['ContractNo']+'</div>'+
				'<div class="textTip">合同签订日期</div><div class="textContent">'+pageData['SignDate']+'</div>'+
				'<div class="textTip">合同生效日期</div><div class="textContent">'+pageData['ValidDate']+'</div>'+
				'<div class="textTip">转让金额(万元)</div><div class="textContent">'+pageData['TransAmount']+'</div>'+
				'<div class="textTip">到账日期</div><div class="textContent">'+pageData['ReceiptDate']+'</div>'+
				'<div class="textTip">已到账金额(万元)</div><div class="textContent">'+pageData['ReceivedAmount']+'</div>'+
				'<div class="textTip">第一完成人</div><div class="textContent">'+
					pageData['FirstPerDesc']+' - '+pageData['FirstNo']+' - '+pageData['FirstLvDesc']+'<br />'+
						pageData['FirstHireDesc']+' - '+pageData['FirstPostDesc']+'<br />'+
						pageData['FirstBigDesc']+'<br />'+pageData['FirstLocDesc']+'</div>'+
				'<div class="textTip">第二完成人</div><div class="textContent">'+
					pageData['SecPerDesc']+' - '+pageData['SecNo']+' - '+(pageData['SecLvDesc']||'')+'<br />'+
						(pageData['SecHireDesc']||'')+' - '+(pageData['SecPostDesc']||'')+'<br />'+
						(pageData['SecBigDesc']||'')+'<br />'+(pageData['SecLocDesc']||'')+'</div>'+
				'<div class="textTip">第三完成人</div><div class="textContent">'+
					pageData['ThirdPerDesc']+' - '+pageData['ThirdNo']+' - '+(pageData['ThirdLvDesc']||'')+'<br />'+
						(pageData['ThirdHireDesc']||'')+' - '+(pageData['ThirdPostDesc']||'')+'<br />'+
						(pageData['ThirdBigDesc']||'')+'<br />'+(pageData['ThirdLocDesc']||'')+'</div>'+
				'<div class="textTip">其它完成人</div><div class="textContent">'+pageData['OtherPer']+'</div>'
		}
		html += '<div class="textTip">附件</div><div class="textContent">'+getDetailFileHtml(pageData['Files'],1,TomcatUrl,pageData['RowID'])+'</div>';
		scroll.innerHTML = html;
		setupDetailFileTap('scroll')
		if (fromPage == 'person-info') {
			return;
		}
		setupBtnTapped();
	}
	
	
	//
	//opStr:通过A 拒绝R
	function agreeRefuseAction(btnId,reasonText){
		//最高权限 4护士长 3总护士长 总结:小于3 护理部权限 等于3或4是护士长
		var opStr = 'A';//未审核Y 护士长审核通过A  护理部审核通过R   作废N  驳回B
		if (btnId == 'refuseApply') {
			opStr = 'B'
		}else if (maxRole < 3) {
			if(maxRole != 0){
				opStr = 'R'
			}else{
				mui.toast('用户未配置角色，请联系管理员登录护理管理系统，进入“系统设置” -> ”用户角色设置”进行配置！')
				return
			}
		}
		plus.nativeUI.showWaiting("正在审核",{modal:false});
		var parr = 'RowID|'+rw+'^'+statusKey+'|'+opStr;
		var pdict = {'className':className,rowIdKey:'RowID',parr: parr}
		var paramDict = {'method':method,'params':JSON.stringify(pdict),'type':'Method'}
		// console.log(JSON.stringify(pdict))
		mui.DHCWebService(paramDict, function(result) {
			plus.nativeUI.closeWaiting();
			 // console.log(JSON.stringify(result));
			if (result.msgcode != '1') {
				mui.toast(result.msg)
				return
			}
			plus.storage.setItem('detail','1');
			mui.back();
		}, function(errorStr) {
			mui.toast(errorStr);
			plus.nativeUI.closeWaiting();
		});
	}
	
	function setupBtnTapped(){
		var wrapper = document.getElementById('wrapper');
		wrapper.style.bottom = '50px';
		var refuseApply = document.getElementById('refuseApply');
		refuseApply.style.display = 'block';
		refuseApply.addEventListener('tap', agreeRefuseBtnTapped, false);
		var agreeApply = document.getElementById('agreeApply');
		agreeApply.style.display = 'block';
		agreeApply.addEventListener('tap', agreeRefuseBtnTapped, false);
	}
	function agreeRefuseBtnTapped(event){
		var btnId = event.target.id;
		var tipStr = '确定审批通过这条数据吗？'
		if (btnId == 'refuseApply') {
			tipStr = '确定驳回这条数据吗？'
		}
		mui.confirm(tipStr,'温馨提示',['取消','确定'],function(e){
			if (e.index == 1) {
				agreeRefuseAction(btnId,'')
			}
		});
	}
	
	function scrollToBottom(){
		var dom = document.getElementById('wrapper');
		var maxScrollY = dom.clientHeight - dom.querySelector('.mui-scroll').clientHeight;
		if (maxScrollY >= 0) {			
			return;
		}
		mui('#wrapper').scroll().scrollTo(0,maxScrollY,100);
		mui('#wrapper').scroll().reLayout();
	}
	
})(mui);